/**
 * Created by Administrator on 2018/6/20.
 */

$CertusJsonAjax.ajax("queryBidProcessTrace",{
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
},function(res){
    $$scope.processs = res.data;
})

$CertusJsonAjax.ajax('bidBaseInfo', {
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
}, function (res) {
    $$scope.permissionSelect = [
        {name: '请选择', value: "xxxx"},
        {name: '总经理', value: "0"},
        {name: '总监', value: "1"},
        {name: '本部门', value: "2"}
    ]

    var picker2 = $('#datetime').datetimepicker({
        format: 'YYYY-MM-DD',
        locale: moment.locale('zh-cn')
    }).on('dp.change', function (e) {
        var result = new moment(e.date).format('YYYY-MM-DD');
        if (result && !angular.isUndefined(result)) {
            $$scope.file.validity = result;
            $$scope.$apply();
        }
    })

    $$scope.bid = res.data;
    $$scope.bid.processInstanceId = $CertusJsonAjax.getProInstanceId();
    $$scope.bid.stepInstanceId = $CertusJsonAjax.getStepInstanceId();
})

$$scope.shutdown = function () {
    $CertusJsonAjax.ajax("bidshutdown", $$scope.bid, function (res) {
        history.back();
    })
}

var fileInstantiation = {
    classCateCode: 'NBCPYZ',
    fileClassCode: 'TBJFFA'
}
var fileInstantiationDisable = {
    classCateCodeDis: true, //文件类目不可修改
    fileClassCodeDis: true //文件类型不可修改
}
//调用初始化方法
initFileUpload($$scope, fileInstantiation, fileInstantiationDisable, $CertusFormAjax);

function hidefile1() {
    if(certusValidateNotnullPolyfill()){
        $(".hidefile").hide();
    }
}

$$scope.formSubmitted = function () {

    if(certusValidateNotnull() && $$scope.bid.specifiedMan && $$scope.bid.specifiedMan != ""){
        $$scope.bid.nameOfPage = "交付方案";
        $$scope.bid.pathFrom = "selbidC";

        fileUpload($$scope, function (res) {
            $$scope.bid.uploadFilePath = res.data;
            $CertusJsonAjax.ajax("bidSubmit", $$scope.bid, function (res) {
                layer.msg("提交成功");
                history.back();
            })
        }, function () {
            $CertusJsonAjax.ajax("bidSubmit", $$scope.bid, function () {
                history.back();
            })
        }, $CertusFormAjax);
    }else{
        layer.msg("请补全相关信息")
    }

}

//文件上传统一字段
function showfile() {
    $(".hidefile").show();
}

function hidefile() {
    $$scope.file = {};
    initFileUpload($$scope, fileInstantiation, fileInstantiationDisable, $CertusFormAjax);
    $(".hidefile").hide();
}



$$scope.getsssbbb = function(bb){
    if(bb == "starting"){
        return "正在进行中";
    }else if(bb == "denied"){
        return "否决";
    }else if(bb == "sentback"){
        return "被退";
    }else if(bb == "others"){
        return "关闭";
    }else if(bb == "completed"){
        return "完成";    }else if(bb == "terminated"){        return "终结";    }    else if(bb == "cancelled"){        return "通过";}
    return "待办";
}